package com.qqtech.qquan.activity.dao;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import com.qqtech.core.common.util.BeanUtil;
import com.qqtech.core.frame.dao.BaseDaoImpl;
import com.qqtech.qquan.activity.model.ActivityBase;
import com.qqtech.qquan.activity.model.ActivityBaseQuery;
import com.qqtech.qquan.activity.model.ActivityBaseVo;

@Repository
public class ActivityBaseDaoImpl extends BaseDaoImpl<ActivityBase> implements ActivityBaseDao {
	public static final Logger log = LoggerFactory.getLogger(ActivityBaseDaoImpl.class);

	@Override
	public int updatePv(Integer id) {
		return sqlSessionTemplate.update(getSqlName("updateAddPv"), id);
	}

	@Override
	public List<ActivityBaseVo> queryListByCircle(ActivityBaseQuery query, Pageable pageable) {
		return this.sqlSessionTemplate.selectList(getSqlName("selectListByCircle"), getParams(query, pageable));
	}

	@Override
	public Page<ActivityBaseVo> queryPageByCircle(ActivityBaseQuery query, Pageable pageable) {
		List<ActivityBaseVo> contentList = this.sqlSessionTemplate.selectList(getSqlName("selectListByCircle"),
				getParams(query, pageable));
		return new PageImpl<ActivityBaseVo>(contentList, pageable, queryCountByCircle(query));
	}

	public int queryCountByCircle(ActivityBaseQuery query) {
		return ((Integer) this.sqlSessionTemplate.selectOne(getSqlName("selectCountByCircle"), BeanUtil.toMap(query)))
				.intValue();
	}

	@Override
	public List<ActivityBaseVo> queryActivityByUserId(Integer userId) {
		return sqlSessionTemplate.selectList(getSqlName("selectByUserId"), userId);
	}
}
